/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package pe.edu.aprolab.base.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import pe.edu.aprolab.base.model.Local;
import pe.edu.aprolab.base.model.LocalModel;
import pe.edu.aprolab.base.model.LocalSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Local service. Represents a row in the &quot;BASE_Local&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link pe.edu.aprolab.base.model.LocalModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link LocalImpl}.
 * </p>
 *
 * @author Jorge Loayza Soloisolo
 * @see LocalImpl
 * @see pe.edu.aprolab.base.model.Local
 * @see pe.edu.aprolab.base.model.LocalModel
 * @generated
 */
@JSON(strict = true)
public class LocalModelImpl extends BaseModelImpl<Local> implements LocalModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a local model instance should use the {@link pe.edu.aprolab.base.model.Local} interface instead.
	 */
	public static final String TABLE_NAME = "BASE_Local";
	public static final Object[][] TABLE_COLUMNS = {
			{ "localId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "nombre", Types.VARCHAR },
			{ "estado", Types.INTEGER }
		};
	public static final String TABLE_SQL_CREATE = "create table BASE_Local (localId LONG not null primary key,companyId LONG,nombre VARCHAR(75) null,estado INTEGER)";
	public static final String TABLE_SQL_DROP = "drop table BASE_Local";
	public static final String ORDER_BY_JPQL = " ORDER BY local.nombre ASC";
	public static final String ORDER_BY_SQL = " ORDER BY BASE_Local.nombre ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.pe.edu.aprolab.base.model.Local"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.pe.edu.aprolab.base.model.Local"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.pe.edu.aprolab.base.model.Local"),
			true);
	public static long NOMBRE_COLUMN_BITMASK = 1L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Local toModel(LocalSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Local model = new LocalImpl();

		model.setLocalId(soapModel.getLocalId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setNombre(soapModel.getNombre());
		model.setEstado(soapModel.getEstado());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Local> toModels(LocalSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Local> models = new ArrayList<Local>(soapModels.length);

		for (LocalSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.pe.edu.aprolab.base.model.Local"));

	public LocalModelImpl() {
	}

	@Override
	public long getPrimaryKey() {
		return _localId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setLocalId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _localId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Class<?> getModelClass() {
		return Local.class;
	}

	@Override
	public String getModelClassName() {
		return Local.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("localId", getLocalId());
		attributes.put("companyId", getCompanyId());
		attributes.put("nombre", getNombre());
		attributes.put("estado", getEstado());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long localId = (Long)attributes.get("localId");

		if (localId != null) {
			setLocalId(localId);
		}

		Long companyId = (Long)attributes.get("companyId");

		if (companyId != null) {
			setCompanyId(companyId);
		}

		String nombre = (String)attributes.get("nombre");

		if (nombre != null) {
			setNombre(nombre);
		}

		Integer estado = (Integer)attributes.get("estado");

		if (estado != null) {
			setEstado(estado);
		}
	}

	@JSON
	@Override
	public long getLocalId() {
		return _localId;
	}

	@Override
	public void setLocalId(long localId) {
		_localId = localId;
	}

	@JSON
	@Override
	public long getCompanyId() {
		return _companyId;
	}

	@Override
	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	@Override
	public String getNombre() {
		if (_nombre == null) {
			return StringPool.BLANK;
		}
		else {
			return _nombre;
		}
	}

	@Override
	public void setNombre(String nombre) {
		_columnBitmask = -1L;

		if (_originalNombre == null) {
			_originalNombre = _nombre;
		}

		_nombre = nombre;
	}

	public String getOriginalNombre() {
		return GetterUtil.getString(_originalNombre);
	}

	@JSON
	@Override
	public int getEstado() {
		return _estado;
	}

	@Override
	public void setEstado(int estado) {
		_estado = estado;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
			Local.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Local toEscapedModel() {
		if (_escapedModel == null) {
			_escapedModel = (Local)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelInterfaces, new AutoEscapeBeanHandler(this));
		}

		return _escapedModel;
	}

	@Override
	public Object clone() {
		LocalImpl localImpl = new LocalImpl();

		localImpl.setLocalId(getLocalId());
		localImpl.setCompanyId(getCompanyId());
		localImpl.setNombre(getNombre());
		localImpl.setEstado(getEstado());

		localImpl.resetOriginalValues();

		return localImpl;
	}

	@Override
	public int compareTo(Local local) {
		int value = 0;

		value = getNombre().compareTo(local.getNombre());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof Local)) {
			return false;
		}

		Local local = (Local)obj;

		long primaryKey = local.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		LocalModelImpl localModelImpl = this;

		localModelImpl._originalNombre = localModelImpl._nombre;

		localModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Local> toCacheModel() {
		LocalCacheModel localCacheModel = new LocalCacheModel();

		localCacheModel.localId = getLocalId();

		localCacheModel.companyId = getCompanyId();

		localCacheModel.nombre = getNombre();

		String nombre = localCacheModel.nombre;

		if ((nombre != null) && (nombre.length() == 0)) {
			localCacheModel.nombre = null;
		}

		localCacheModel.estado = getEstado();

		return localCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(9);

		sb.append("{localId=");
		sb.append(getLocalId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", nombre=");
		sb.append(getNombre());
		sb.append(", estado=");
		sb.append(getEstado());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(16);

		sb.append("<model><model-name>");
		sb.append("pe.edu.aprolab.base.model.Local");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>localId</column-name><column-value><![CDATA[");
		sb.append(getLocalId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>nombre</column-name><column-value><![CDATA[");
		sb.append(getNombre());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>estado</column-name><column-value><![CDATA[");
		sb.append(getEstado());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Local.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] { Local.class };
	private long _localId;
	private long _companyId;
	private String _nombre;
	private String _originalNombre;
	private int _estado;
	private long _columnBitmask;
	private Local _escapedModel;
}